import os.path


class Cache(object):
    def __init__(self, label, storage_object):
        self.cache = storage_object
        self.file = 'cache/' + label + '.cache'
        self.load()

    def load(self):
        if os.path.isfile(self.file):
            print 'reading cache %s' % self.file
            with open(self.file, 'r') as f:
                cache = f.read()
                try:
                    self.cache = eval(cache)
                except Exception, e:
                    print e

    def save(self):
        f = open(self.file, 'w')
        f.write(str(self.cache))
        f.close()
